/*
 * This file is part of the Try! Engine project.
 *
 * Copyright 2010-2011 Emanuele Bertoldi. All rights reserved.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * You should have received a copy of the modified BSD License along with this
 * program. If not, see <http://www.opensource.org/licenses/bsd-license.php>
 */

#include "logic.h"
#include <audiolistener.h>
#include <audiosource.h>
#include <cameracontroller.h>
#include <lightemitter.h>
#include <model3d.h>
#include <scenetransformable.h>
#include <application.h>

int main(int argc, char** argv)
{
    Logic app_logic;

    Try::Application app(&app_logic);

    // Set a camera to render the scene...
    Try::RenderWindow* win = app.window();
    Try::CameraNode* camera = new CameraNode("Camera", "pipelines/forward.pipeline.xml", win->width(), win->height(), 45.0f);
    win->setActiveCamera(camera);

    // ...then add some useful properties to the "app" object...
    Try::CameraController cam_ctrl(&app, camera);
    Try::AudioListener audio_lst(&app, camera->transform().position);

    // ...add a ground...
    Try::Object env("Environment");
    Try::Model3D env_model(&env, "models/tiles/tiles.scene.xml");
    env_model.setPosition(Vector3(0, -1, -12));
    env_model.setScale(Vector3(4, 0.01f, 4));

    // ..two sound sources...
    Try::Object ss1("Sound Source 1");
    Try::Model3D ss1_model(&env, "models/speaker/speaker.scene.xml");
    ss1_model.setPosition(Vector3(-6, -1, -15));
    ss1_model.setScale(Vector3(2, 2, 2));
    ss1_model.lookAt(Vector3(0, -1, 0));
    Try::AudioSource as1(&ss1, "sounds/test1.wav", ss1_model.position());
    as1.play(true);

    Try::Object ss2("Sound Source 2");
    Try::Model3D ss2_model(&env, "models/speaker/speaker.scene.xml");
    ss2_model.setPosition(Vector3(6, -1, -15));
    ss2_model.setScale(Vector3(2, 2, 2));
    ss2_model.lookAt(Vector3(0, -1, 0));
    Try::AudioSource as2(&ss2, "sounds/test2.wav", ss2_model.position());
    as2.play(true);

    // ...and also a light.
    Try::Object light("Light");
    Try::LightEmitter light_emitter(&light, light.name());
    light_emitter.setPosition(Vector3(0, 20, 50));

    return app.run();
}
